import * as THREE from 'three';
export function lanToCoord (e, t, a) {
  return [Math.cos(e / 180 * Math.PI) * Math.cos(t / 180 * Math.PI) * a, Math.sin(t / 180 * Math.PI) * a, -Math.sin(e / 180 * Math.PI) * Math.cos(t / 180 * Math.PI) * a]
}
export function lanToVector3(e, t, a) {
  return new THREE.Vector3(Math.cos(e / 180 * Math.PI) * Math.cos(t / 180 * Math.PI) * a, Math.sin(t / 180 * Math.PI) * a, -Math.sin(e / 180 * Math.PI) * Math.cos(t / 180 * Math.PI) * a)
}

export function drawInfoCard(item) {
  var canvas = document.createElement('canvas')
  canvas.width = 404
  canvas.height = 244
  var ctx = canvas.getContext('2d')
  ctx.fillStyle = 'rgba(255, 255, 255, 0.2)'
  ctx.fillRect(0, 0, 404, 244);
  ctx.beginPath()
  ctx.lineWidth = 4
  ctx.strokeStyle = '#fff'
  ctx.rect(2, 2, 400, 240)
  ctx.stroke()
  ctx.font = '40px 微软雅黑'
  ctx.fillStyle = '#fff'
  ctx.textAlign = 'left'
  ctx.textBaseline = 'top'
  ctx.fillText(item.name, 20, 26)
  ctx.font = '20px 微软雅黑'
  ctx.fillText(`人口：${item.population}万人`, 20, 80)
  ctx.fillText(`GDP：${item.gdp}元`, 20, 110)
  return canvas
}
export function drawLabel(text, config) {
  var canvas = document.createElement('canvas')
  var ctx = canvas.getContext('2d')
  canvas.height = config.fontSize
  ctx.font = 'normal '.concat(config.fontSize, 'px ').concat(config.fontFamily)
  var width = ctx.measureText(text).width
  canvas.width = width
  ctx.textBaseline="top"; 
  ctx.font = 'normal '.concat(config.fontSize, 'px ').concat(config.fontFamily)
  ctx.fillStyle = config.color
  ctx.fillText(text, 1, 1)
  return canvas
}